#ifndef __NODE_H__
#define __NODE_H__

#include <vector>
#include <string>
#include <map>
#include <utility>
#include <sstream>
#include <iostream>
#include <ostream>

#include "OSThread.h"
#include "Messenger.h"
class Mailer;
typedef vector<int>::iterator viter;
typedef map<int,pair<int, int>  >::iterator miter;

using namespace std;

class Node:public OSThread,public Messenger{
private:
    //node id
    int id;
    //mailer pointer for msg sending:
    Mailer* mailer;
    //RT
    //map: node id -> <distance, node>
    map<int,pair<int , int> > RT;

    //neighbors
    vector<int> neighbors;
    void studendYield();
    void resetRT(int num);
    void distRT();
    void accumulate();

public:
	//enum { active= 0, yeilded=1, blocked=2 };
    bool stable;
    int currentStatus;
    int previousStatus;
    bool yielded;
    bool active;
    bool blocked;
    int accumulator;
    int quantaAccumulator;
    int priority;
    //ctor:
    Node(int id,string neighbors, int numOfNodes,Mailer* mailer);
    ~Node();


    int getID();
    vector<int> getNeighbors();
    //node, <distance, routing>
    map<int ,pair<int, int> > getRT();
    string toString();
    string printRT();
    void updateRT(map<int,pair<int , int> >* other, int senderID);
    void handleSysMsg(Message* msg);
    void handleRTMsg(Message* msg);
    void handleMsg(Message* msg);
    void studentSetQuanta(int n);


//virtuals:

    /* run - an abstract method that will be called when the
     * thread starts running */
    void run();

    /* studentSend - an abstract method that is used to send the message you wish to send */
    bool studentSend(void *args);

    /* studentRecv - an abstract method that is used to receive a message */
    bool studentRecv(void **args);



};
#endif
